package com.mr.web.controller;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.mr.web.dwr.DWRRequestProcessor;
import com.mr.web.dwr.DWRUtils;
public class StartupListener extends ContextLoaderListener implements
      ServletContextListener {
	@Override
   public void contextInitialized(ServletContextEvent event) {
      super.contextInitialized(event);
      ServletContext context = event.getServletContext();
      setupContext(context);
   }

   public static void setupContext(ServletContext context) {
      WebApplicationContext ctx = WebApplicationContextUtils
            .getRequiredWebApplicationContext(context);
      DWRUtils.setContext(context);
      DWRUtils.setAppContext(ctx);
      DWRRequestProcessor.setAppContext(ctx);
   }
}
